package com.bdqn.zhao.controller;

import com.bdqn.zhao.config.Constants;
import com.bdqn.zhao.config.ServletUtils;
import com.bdqn.zhao.pojo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);


    public String getLoginName() {
        return getRequest().getHeader(Constants.CURRENT_USERNAME);
    }


    /**
     * 获取request
     */
    public HttpServletRequest getRequest() {
        return ServletUtils.getRequest();
    }

    /**
     * 响应返回结果
     *
     * @param rows 影响行数
     * @return 操作结果
     */
    protected R toAjax(int rows) {
        return rows > 0 ? R.ok() : R.error();
    }

    /**
     * 响应返回结果
     *
     * @param result 结果
     * @return 操作结果
     */
    protected R toAjax(boolean result) {
        return result ? R.ok() : R.error();
    }


}
